package com.umeng.analytics.pro;

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

public class cy extends df {
    public static class a implements dh {
        protected boolean a;
        protected boolean b;
        protected int c;

        public a() {
            this(false, true);
        }

        public a(boolean arg2, boolean arg3) {
            this(arg2, arg3, 0);
        }

        public a(boolean arg2, boolean arg3, int arg4) {

            this.a = false;
            this.b = true;
            this.a = arg2;
            this.b = arg3;
            this.c = arg4;
        }

        public df a(dt arg4) {
            cy v0 = new cy(arg4, this.a, this.b);
            if(this.c != 0) {
                v0.c(this.c);
            }

            return ((df)v0);
        }
    }

    protected static final int a = -65536;
    protected static final int b = -2147418112;
    protected boolean c;
    protected boolean d;
    protected int e;
    protected boolean f;
    private static final dk h = new dk();
    private byte[] i;
    private byte[] j;
    private byte[] k;
    private byte[] l;
    private byte[] m;
    private byte[] n;
    private byte[] o;
    private byte[] p;

    public cy(dt arg3) {
        this(arg3, false, true);
    }

    public cy(dt arg6, boolean arg7, boolean arg8) {
        super(arg6);
        this.c = false;
        this.d = true;
        this.f = false;
        this.i = new byte[1];
        this.j = new byte[2];
        this.k = new byte[4];
        this.l = new byte[8];
        this.m = new byte[1];
        this.n = new byte[2];
        this.o = new byte[4];
        this.p = new byte[8];
        this.c = arg7;
        this.d = arg8;
    }

    public ByteBuffer A() throws cm {
        ByteBuffer v0;
        int v1 = this.w();
        this.d(v1);
        if(this.g.h() >= v1) {
            v0 = ByteBuffer.wrap(this.g.f(), this.g.g(), v1);
            this.g.a(v1);
        }
        else {
            byte[] v0_1 = new byte[v1];
            this.g.d(v0_1, 0, v1);
            v0 = ByteBuffer.wrap(v0_1);
        }

        return v0;
    }

    private int a(byte[] arg2, int arg3, int arg4) throws cm {
        this.d(arg4);
        return this.g.d(arg2, arg3, arg4);
    }

    public void a() {
    }

    public void a(byte arg5) throws cm {
        this.i[0] = arg5;
        this.g.b(this.i, 0, 1);
    }

    public void a(double arg4) throws cm {
        this.a(Double.doubleToLongBits(arg4));
    }

    public void a(long arg10) throws cm {
        this.l[0] = ((byte)(((int)(arg10 >> 56 & 255))));
        this.l[1] = ((byte)(((int)(arg10 >> 48 & 255))));
        this.l[2] = ((byte)(((int)(arg10 >> 40 & 255))));
        this.l[3] = ((byte)(((int)(arg10 >> 32 & 255))));
        this.l[4] = ((byte)(((int)(arg10 >> 24 & 255))));
        this.l[5] = ((byte)(((int)(arg10 >> 16 & 255))));
        this.l[6] = ((byte)(((int)(arg10 >> 8 & 255))));
        this.l[7] = ((byte)(((int)(255 & arg10))));
        this.g.b(this.l, 0, 8);
    }

    public void a(int arg5) throws cm {
        this.k[0] = ((byte)(arg5 >> 24 & 255));
        this.k[1] = ((byte)(arg5 >> 16 & 255));
        this.k[2] = ((byte)(arg5 >> 8 & 255));
        this.k[3] = ((byte)(arg5 & 255));
        this.g.b(this.k, 0, 4);
    }

    public void a(da arg2) throws cm {
        this.a(arg2.b);
        this.a(arg2.c);
    }

    public void a(short arg5) throws cm {
        this.j[0] = ((byte)(arg5 >> 8 & 255));
        this.j[1] = ((byte)(arg5 & 255));
        this.g.b(this.j, 0, 2);
    }

    public void a(db arg2) throws cm {
        this.a(arg2.a);
        this.a(arg2.b);
    }

    public void a(dc arg2) throws cm {
        this.a(arg2.a);
        this.a(arg2.b);
        this.a(arg2.c);
    }

    public void a(dd arg3) throws cm {
        if(this.d) {
            this.a(-2147418112 | arg3.b);
            this.a(arg3.a);
            this.a(arg3.c);
        }
        else {
            this.a(arg3.a);
            this.a(arg3.b);
            this.a(arg3.c);
        }
    }

    public void a(String arg5) throws cm {
        try {
            byte[] v0_1 = arg5.getBytes("UTF-8");
            this.a(v0_1.length);
            this.g.b(v0_1, 0, v0_1.length);
            return;
        }
        catch(UnsupportedEncodingException v0) {
            throw new cm("JVM DOES NOT SUPPORT UTF-8");
        }
    }

    public void a(dj arg2) throws cm {
        this.a(arg2.a);
        this.a(arg2.b);
    }

    public void a(dk arg1) {
    }

    public void a(ByteBuffer arg6) throws cm {
        int v0 = arg6.limit() - arg6.position();
        this.a(v0);
        this.g.b(arg6.array(), arg6.position() + arg6.arrayOffset(), v0);
    }

    public void a(boolean arg2) throws cm {
        byte v0 = (byte) (arg2 ? 1 : 0);
        this.a(v0);
    }

    public String b(int arg4) throws cm {
        try {
            this.d(arg4);
            byte[] v0_1 = new byte[arg4];
            this.g.d(v0_1, 0, arg4);
            return new String(v0_1, "UTF-8");
        }
        catch(UnsupportedEncodingException v0) {
            throw new cm("JVM DOES NOT SUPPORT UTF-8");
        }
    }

    public void b() {
    }

    public void c() {
    }

    public void c(int arg2) {
        this.e = arg2;
        this.f = true;
    }

    protected void d(int arg4) throws cm {
        if(arg4 < 0) {
            throw new dg("Negative length: " + arg4);
        }

        if(this.f) {
            this.e -= arg4;
            if(this.e < 0) {
                throw new dg("Message length exceeded: " + arg4);
            }
        }
    }

    public void d() throws cm {
        this.a(0);
    }

    public void e() {
    }

    public void f() {
    }

    public void g() {
    }

    public dd h() throws cm {
        dd v0;
        int v3 = 4;
        int v1 = this.w();
        if(v1 < 0) {
            if((-65536 & v1) != -2147418112) {
                throw new dg(v3, "Bad version in readMessageBegin");
            }
            else {
                v0 = new dd(this.z(), ((byte)v1), this.w());
            }
        }
        else if(this.c) {
            throw new dg(v3, "Missing version in readMessageBegin, old client?");
        }
        else {
            v0 = new dd(this.b(v1), this.u(), this.w());
        }

        return v0;
    }

    public void i() {
    }

    public dk j() {
        return cy.h;
    }

    public void k() {
    }

    public da l() throws cm {
        byte v1 = this.u();
        short v0 = v1 == 0 ? 0 : this.v();
        return new da("", v1, v0);
    }

    public void m() {
    }

    public dc n() throws cm {
        return new dc(this.u(), this.u(), this.w());
    }

    public void o() {
    }

    public db p() throws cm {
        return new db(this.u(), this.w());
    }

    public void q() {
    }

    public dj r() throws cm {
        return new dj(this.u(), this.w());
    }

    public void s() {
    }

    public boolean t() throws cm {
        boolean v0 = true;
        if(this.u() != 1) {
            v0 = false;
        }

        return v0;
    }

    public byte u() throws cm {
        byte v0;
        if(this.g.h() > 0) {
            v0 = this.g.f()[this.g.g()];
            this.g.a(1);
        }
        else {
            this.a(this.m, 0, 1);
            v0 = this.m[0];
        }

        return v0;
    }

    public short v() throws cm {
        int v0 = 0;
        int v3 = 2;
        byte[] v1 = this.n;
        if(this.g.h() >= v3) {
            v1 = this.g.f();
            v0 = this.g.g();
            this.g.a(v3);
        }
        else {
            this.a(this.n, 0, v3);
        }

        return ((short)(v1[v0 + 1] & 255 | (v1[v0] & 255) << 8));
    }

    public int w() throws cm {
        int v0 = 0;
        int v3 = 4;
        byte[] v1 = this.o;
        if(this.g.h() >= v3) {
            v1 = this.g.f();
            v0 = this.g.g();
            this.g.a(v3);
        }
        else {
            this.a(this.o, 0, v3);
        }

        return v1[v0 + 3] & 255 | ((v1[v0] & 255) << 24 | (v1[v0 + 1] & 255) << 16 | (v1[v0 + 2] & 255) << 8);
    }

    public long x() throws cm {
        int v0 = 0;
        int v7 = 8;
        byte[] v1 = this.p;
        if(this.g.h() >= v7) {
            v1 = this.g.f();
            v0 = this.g.g();
            this.g.a(v7);
        }
        else {
            this.a(this.p, 0, v7);
        }

        return (((long)(v1[v0 + 7] & 255))) | ((((long)(v1[v0] & 255))) << 56 | (((long)(v1[v0 + 1] & 255))) << 48 | (((long)(v1[v0 + 2] & 255))) << 40 | (((long)(v1[v0 + 3] & 255))) << 32 | (((long)(v1[v0 + 4] & 255))) << 24 | (((long)(v1[v0 + 5] & 255))) << 16 | (((long)(v1[v0 + 6] & 255))) << v7);
    }

    public double y() throws cm {
        return Double.longBitsToDouble(this.x());
    }

    public String z() throws cm {
        String v0_1;
        int v1 = this.w();
        if(this.g.h() >= v1) {
            try {
                v0_1 = new String(this.g.f(), this.g.g(), v1, "UTF-8");
                this.g.a(v1);
            }
            catch(UnsupportedEncodingException v0) {
                throw new cm("JVM DOES NOT SUPPORT UTF-8");
            }
        }
        else {
            v0_1 = this.b(v1);
        }

        return v0_1;
    }
}

